package private

import (
	"dc-go/global"
	"dc-go/model"
)

type ServiceLogLogin struct{}

func (s *ServiceLogLogin) GetLogLoginList(requestLogList model.RequestGetLogLoginList) (err error, role interface{}, total int64) {
	pageSize := requestLogList.PageSize
	offset := requestLogList.PageSize * (requestLogList.Page - 1)
	db := global.DcDb.Model(&model.SysLogLogin{})
	var logList []model.SysLogLogin
	//配置搜索
	if requestLogList.LoginEmpeeAcct != "" {
		db = db.Where("login_empee_acct like ?", "%"+requestLogList.LoginEmpeeAcct+"%")
	}
	if requestLogList.LoginSuccess != "" {
		db = db.Where("login_success = ?", requestLogList.LoginSuccess)
	}
	err = db.Count(&total).Error
	if err != nil {
		return
	}
	err = db.Limit(pageSize).Offset(offset).Order(model.OrderByColumn(requestLogList.SortBy, requestLogList.Desc)).Find(&logList).Error
	return err, logList, total
}

func (s *ServiceLogLogin) DeleteLogLoginById(id uint) (err error) {
	var sysLog model.SysLogLogin
	if err = global.DcDb.Where("id = ?", id).First(&sysLog).Error; err != nil {
		return err
	}
	err = global.DcDb.Where("id = ?", id).Unscoped().Delete(&sysLog).Error
	return err
}
